package javabase.nio;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.AsynchronousSocketChannel;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

public class AIOClient {
	
	private AsynchronousSocketChannel client = null;
	
	public AIOClient() throws IOException, InterruptedException, ExecutionException {
		this.client = AsynchronousSocketChannel.open();
		Future<?> future = client.connect(new InetSocketAddress("127.0.0.1",8888));
		System.out.println(future.get());
	}
	
	public void write(byte b) {
		ByteBuffer buffer = ByteBuffer.allocate(100);
		buffer.put(b);
		buffer.flip();
		client.write(buffer);
	}
	
	public static void main(String[] args) throws IOException, InterruptedException, ExecutionException {
		AIOClient client = new AIOClient();
		
		client.write((byte) 67);
	}
	
}
